﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using AspNetCs.Common;
using System.Text;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.Channel_Enum;
using System.Data;

public partial class memorial_Sacrifice : BasePage
{
    protected int id = 0;
    protected memorial_model mdel = new memorial_model();
    protected string types = "";
    protected string infolist = "";
    protected int CurrPage = 1;
    protected int pagesize = 10;
    protected string filter = "";
    protected int Recordsum = 0;
    protected int SumPage = 0;
    protected string ActionType = "";
    protected string ChannelId = "";
    protected void Page_Load(object sender, EventArgs e)
    {


        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.AddHeader("Pragma", "No-Cache");

        if (Request["types"] != null)
        {
            types = Request["types"].ToString();
        }
        if (Request["ChannelId"] != null)
        {
            ChannelId = Request["ChannelId"].ToString();
        }

        if (Request["ActionType"] != null)
        {
            ActionType = Request["ActionType"].ToString();
            if (ActionType == "SaveAlms")
            {
                int meid = 0;
                string GDName = "";
                string Mail = "";
                string Readme = "";
                decimal GDmoney = 0;
                int AlmsTypes = 2;
                int State = 0;
                string ReUrlAdr = "";

                if (Request["meid"] != null)
                {
                    meid = StringHelper.isNumber_int(Request["meid"].ToString());
                }



                if (Request["ReUrlAdr"] != null)
                {
                    ReUrlAdr = Request["ReUrlAdr"].ToString();
                }



                if (Request["AlmsTypes"] != null)
                {
                    AlmsTypes = StringHelper.isNumber_int(Request["AlmsTypes"].ToString());
                }



                if (Request["GDName"] != null)
                {
                    GDName = StringHelper.HtmlEncrypt(Request["GDName"].ToString());
                }

                if (Request["Txt_Mail"] != null)
                {
                    Mail = StringHelper.HtmlEncrypt(Request["Txt_Mail"].ToString());
                }


                if (Request["GDContent"] != null)
                {
                    Readme = StringHelper.HtmlEncrypt(Request["GDContent"].ToString());
                }


                if (Request["GDmoney"] != null)
                {
                    GDmoney = StringHelper.isNumber_decimal(Request["GDmoney"].ToString());
                }

                if (AlmsTypes == 1)
                {
                    if (Base_GetLoginInfo.GetUserID <= 0)
                    {
                        Response.Write("<script>alert('请您登录以后才能直接进行用户扣点捐助!');history.back();</script>");
                        Response.End();
                    }
                    else
                    {
                        if (Base_GetUserInfo.Point < GDmoney)
                        {
                            Response.Write("<script>alert('您的点数只有" + Base_GetUserInfo.Point + "点，请您先进行充值!');history.back();</script>");
                            Response.End();
                        }
                        else
                        {
                            Channel_Type CType = (Channel_Type)Enum.Parse(typeof(Channel_Type), ChannelId);


                            string TypeStr = EnumDescription.GetFieldText(CType);

                            Point_Log_Model LogMd = new Point_Log_Model();
                            LogMd.Addtime = DateTime.Now;
                            LogMd.NetIp = StringHelper.Ip();
                            LogMd.Point = GDmoney;
                            LogMd.Readme = "捐助ID为" + meid + "的" + TypeStr + GDmoney + "元。地址:<a href='" + ReUrlAdr + "' target='_blank'>" + ReUrlAdr + "</a>";
                            LogMd.UserId = Base_GetLoginInfo.GetUserID;
                            if (Point_Log_Bll.CreateNew.Add(LogMd) > 0)
                            {
                                State = 1;

                            }

                        }
                    }

                }
                else
                {
                    State = 0;
                }

                Alms_Model AlmsMd = new Alms_Model();
                AlmsMd.TrueName = GDName;
                AlmsMd.Email = Mail;
                AlmsMd.UserId = Base_GetLoginInfo.GetUserID;
                AlmsMd.NetIP = StringHelper.Ip();
                AlmsMd.ChannelId = ChannelId;
                AlmsMd.TypeId = meid;
                AlmsMd.Readme = Readme;
                AlmsMd.Almsmoney = Convert.ToDouble(GDmoney);
                AlmsMd.AmsType = AlmsTypes;
                AlmsMd.Addtime = DateTime.Now.ToString();
                AlmsMd.State = State;
                int resultnum = AlmsBll.CreateNew.Add(AlmsMd);
                if (resultnum > 0)
                {
                    if (State == 0)
                    {
                        Response.Write("<script>alert('捐助信息我们已收到,感谢您对本馆的支持!也请您尽快通过以下方式进行汇款，汇款以后我才会开通!');window.open('" + configInfo.InstallDir + "payment.html','newwindow','height=365, width=670, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no,top=100,left=300');location.href='" + ReUrlAdr + "';</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('捐助成功!感谢您对本馆的支持!');location.href='" + ReUrlAdr + "';</script>");
                    }
                }
                Response.End();

            }
        }


        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (Request["CurrPage"] != null)
        {
            CurrPage = StringHelper.isNumber_int(Request["CurrPage"].ToString());
        }



        mdel = Memorial_Bll.CreateNew.GetModel(id);
        if (mdel.Id <= 0)
        {
            ShowMsgBack("错误提示：当前馆号不存在!");
            Response.End();
        }

        StringBuilder newstr = new StringBuilder();
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/jquery.js'></script>");
        newstr.AppendLine("<style type='text/css'>");
        newstr.AppendLine("body,div,table,tr,td{color:#333333;font-size:12px;}");
        newstr.AppendLine("a{color: #000000;text-decoration: none;font-size:14px;}");
        newstr.AppendLine("a:hover {color: #000000;text-decoration: none; font-size:14px;}");
        newstr.AppendLine("</style>");
        Temple_Model md = TempleBll.CreateNew.GetModel(mdel.TempleId);
        string ServerUrl = configInfo.InstallDir + StringHelper.ReadConfig("TempleSkin") + ChannelId.ToLower() + "/" + md.TemplePath.ToString() + "/SacrificeList.html";
        strBuilder = TempleBll.CreateNew.WriteHtml(Server.MapPath(ServerUrl), newstr.ToString());
        DataTable dt = new DataTable();

        if (types == "Sacrifice")
        {
            #region 祭祀列表
            string whestr = " TypeId=" + id + " and channelId='" + ChannelId + "' ";
            Recordsum = SacrificeList_Bll.CreateNew.GetReDataRecord(whestr);


            SumPage = Recordsum / pagesize;
            if ((Recordsum % pagesize) != 0)
            {
                SumPage++;
            }
            if (CurrPage <= 0)
            {
                CurrPage = 1;
            }
            else if (CurrPage > SumPage)
            {
                if (SumPage <= 0)
                {
                    CurrPage = 1;
                }
                else
                {
                    CurrPage = SumPage;
                }

            }

            dt = SacrificeList_Bll.CreateNew.GetDataTable(pagesize, CurrPage, whestr);


            foreach (DataRow dr in dt.Rows)
            {
                int cid = StringHelper.isNumber_int(dr["Classid"].ToString());

                infolist = infolist + "<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'>";
                infolist = infolist + "<tr><td width='130' rowspan='4' align='middle' bgcolor='#FFFFFF'>";
                if (cid <= 0)
                {
                    MusicModel Musicmd = Music_Bll.CreateNew.GetModel(StringHelper.isNumber_int(dr["photoId"].ToString()));
                    infolist = infolist + "<embed src='" + Musicmd.MusicPath + "' width='125' height='28' AUTOSTART='false'></embed>";

                }
                else
                {
                    //UserPhoto_Class_Model PhotoClassmd = UserPhoto_Bll.CreateNew.GetModelClass(cid);
                    UserPhoto_Model Photomd = UserPhoto_Bll.CreateNew.GetModel(StringHelper.isNumber_int(dr["photoId"].ToString()));
                    infolist = infolist + "<img src='" + Photomd.PhotoUrl + "' width=130 height=99 />";
                }
                infolist = infolist + "</td></tr><tr><td valign='top' bgcolor='#FFFFFF'>祭祀人姓名:" + dr["TrueName"].ToString() + "</td></tr>";
                infolist = infolist + "<tr><td height='60' valign='top' bgcolor='#FFFFFF'>留言内容:" + dr["Content"].ToString() + "</td></tr>";
                infolist = infolist + "<tr><td align='right' bgcolor='#f7f7f7'>祭祀时间:" + dr["Addtime"].ToString() + "</td></tr>";
                infolist = infolist + "</table><div style='margin-top:3px;'></div>";
            }
            #endregion

        }

        else
        {
            infolist = infolist + AlmsBll.CreateNew.AlmsAdd(mdel.Names, Base_GetLoginInfo.GetEmail, id.ToString(), ChannelId, "memorial_Sacrifice.Aspx", "/memorialAlms-" + id + ".Aspx");
        }




        if (Recordsum >= pagesize)
        {
            infolist = infolist + ("<table width='90%' border='0' align='center' cellpadding='3' cellspacing='1' bgcolor='#cccccc'>");
            infolist = infolist + ("<tr><td align=right style='font-size:14px;'>");
            infolist = infolist + ("共<strong>" + Recordsum + "</strong>条信息&nbsp;&nbsp;当前第<strong>" + CurrPage + "</strong>页&nbsp;&nbsp;共<strong>" + SumPage + "</strong>页&nbsp;&nbsp;&nbsp;&nbsp;");
            infolist = infolist + ("<a href='memorial_Sacrifice-" + id + "-1.Aspx'>第一页</A>&nbsp;");
            infolist = infolist + ("<A HREF='memorial_Sacrifice-" + id + "-" + (CurrPage - 1) + ".Aspx'>上一页</A>&nbsp;");
            infolist = infolist + ("<A HREF='memorial_Sacrifice-" + id + "-" + (CurrPage + 1) + ".Aspx'>下一页</A>&nbsp;");
            infolist = infolist + ("<A HREF='memorial_Sacrifice-" + id + "-" + SumPage + ".Aspx'>最后一页</A>&nbsp;");
            infolist = infolist + ("转到第<select onChange=\"javascript:location.href='memorial_Sacrifice-" + id + "-'+this.value+'.Aspx'\">");
            for (int i = 1; i <= SumPage; i++)
            {
                if (CurrPage == i)
                {
                    infolist = infolist + ("<option value='" + i + "' Selected  >" + i + "</option>");
                }
                else
                {
                    infolist = infolist + ("<option value='" + i + "'   >" + i + "</option>");
                }

            }
            infolist = infolist + ("</select>页");
            infolist = infolist + ("</td></tr>");
            infolist = infolist + ("</table><br><br><br>");
        }



        GetStringData_lable lbReplace = new GetStringData_lable();
        strBuilder = strBuilder.Replace("[$内容$]", infolist);
        Response.Write(lbReplace.GetResultStr(strBuilder.ToString(), "memorial", Memorial_Bll.CreateNew.GetDataTable(" Where  id=" + id)));


    }
}
